#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 100;

struct ElemType{
    int x, y;
};
struct SqStack{
    ElemType *base;
    ElemType *top;
    int stackSize;
};

void InitStack(SqStack &S){
    S.base = new ElemType[MAXSIZE]; // 将分配的内存的首地址赋值给S.base
    S.top = S.base;
    S.stackSize = MAXSIZE;
}

void Push(SqStack &S, ElemType &e){
    if(S.top - S.base == S.stackSize) return;
    *S.top++ = e;
}

void Pop(SqStack &S, ElemType &e){
    if(S.top == S.base) return;
    e = *--S.top;
}

void GetTop(const SqStack &S, ElemType &e){
    if(S.top == S.base) return;
    e = *(S.top - 1);
}

void Show(const SqStack &S){
    if(S.top == S.base) return;
    ElemType *p = S.top - 1;
    while(p >= S.base){
        cout << p->x << " " << p->y << '\n';
        p--;
    }
}
int main(){
    SqStack S;
    InitStack(S);
    int n; cin >> n;
    while(n--){
        ElemType e;
        cin >> e.x >> e.y;
        Push(S, e);
    }
    Show(S);
    cout << '\n';
    ElemType top;
    GetTop(S, top);
    cout << top.x << " " << top.y << '\n';
    cout << '\n';
    ElemType popTop;
    Pop(S, popTop);
    cout << popTop.x << " " << popTop.y << '\n';
    cout << '\n';
    Show(S);
    return 0;
}